package org.jivesoftware.smackx.pubsub.packet;

import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.Packet;

public final class SyncPacketSend
{
  public static Packet getReply(Connection paramConnection, Packet paramPacket)
    throws XMPPException
  {
    return getReply(paramConnection, paramPacket, SmackConfiguration.getPacketReplyTimeout());
  }

  public static Packet getReply(Connection paramConnection, Packet paramPacket, long paramLong)
    throws XMPPException
  {
    PacketCollector localPacketCollector = paramConnection.createPacketCollector(new PacketIDFilter(paramPacket.getPacketID()));
    paramConnection.sendPacket(paramPacket);
    Packet localPacket = localPacketCollector.nextResult(paramLong);
    localPacketCollector.cancel();
    if (localPacket == null)
      throw new XMPPException("No response from server.");
    if (localPacket.getError() != null)
      throw new XMPPException(localPacket.getError());
    return localPacket;
  }
}